import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { SiteAccountLogService } from '../../services/admin/site-account-log.service';

/**
 * SiteAccountController
 * 对应 PHP: SiteAccount Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('site')
@Controller('adminapi/site')
export class SiteAccountController {
  constructor(private readonly siteAccountLogService: SiteAccountLogService) {}

  /**
   * 站点账户
   * 路由: GET account
   * PHP路由: Route::get('account', 'site.SiteAccount/lists')
   */
  @Get('account')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '站点账户' })
  async lists(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: lists

      return await this.siteAccountLogService.getPage(data);
    } catch (error) {
      throw new BusinessException('lists操作失败', error);
    }
  }

  /**
   * 站点账户
   * 路由: GET account/:id
   * PHP路由: Route::get('account/:id', 'site.SiteAccount/info')
   */
  @Get('account/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '站点账户' })
  async info(@Param('id') id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: info

      return await this.siteAccountLogService.getInfo(id);
    } catch (error) {
      throw new BusinessException('info操作失败', error);
    }
  }

  /**
   * 站点账户
   * 路由: GET account/stat
   * PHP路由: Route::get('account/stat', 'site.SiteAccount/stat')
   */
  @Get('account/stat')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '站点账户' })
  async stat(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: stat

      return await this.siteAccountLogService.stat();
    } catch (error) {
      throw new BusinessException('stat操作失败', error);
    }
  }

  /**
   * 站点账户
   * 路由: GET account/type
   * PHP路由: Route::get('account/type', 'site.SiteAccount/accountType')
   */
  @Get('account/type')
  @ApiOperation({ summary: '站点账户' })
  async accountType() {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: accountType
      // 直接返回字典数据
      return SiteAccountLogDict.getType();
    } catch (error) {
      throw new BusinessException('accountType操作失败', error);
    }
  }
}
